package com.netease.nie.base.utils;

import org.apache.commons.lang.time.DateFormatUtils;

import com.netease.nie.base.exceptions.UnexpectedException;

/**
 * 
 * @author KingsHunter
 * @createDate June 21st,2016
 *
 */
public final class CustomDateFormatUtils {

	private static final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
	private static final String yyyyMMdd = "yyyy-MM-dd";
	private static final String yyyyMMddHHmmssSSS1 = "yyyyMMddHHmmssSSS";
	private static final String yyyyMMddHHmmssSSS2 = "yyyy-MM-dd HH:mm:ss,sss";
	
	public static String getyyyyMMddStr(long timeInMills) {
		if (timeInMills <= 0) 
			throw new UnexpectedException("timeInMills illegal");
		return DateFormatUtils.format(timeInMills, yyyyMMdd);
	}
	
	public static String getyyyyMMddHHmmssStr(long timeInMills) {
		if (timeInMills <= 0) 
			throw new UnexpectedException("timeInMills illegal");
		return DateFormatUtils.format(timeInMills, yyyyMMddHHmmss);
	}
	
	public static String getyyyyMMddHHmmssSSS1Str(long timeInMills) {
		if (timeInMills <= 0) 
			throw new UnexpectedException("timeInMills illegal");
		return DateFormatUtils.format(timeInMills, yyyyMMddHHmmssSSS1);
	}
	
	public static String getyyyyMMddHHmmssSSS2Str(long timeInMills) {
		if (timeInMills <= 0) 
			throw new UnexpectedException("timeInMills illegal");
		return DateFormatUtils.format(timeInMills, yyyyMMddHHmmssSSS2);
	}
	
	public static int getyyyyMMddInt(long timeInMills) {
		return Integer.valueOf(getyyyyMMddStr(timeInMills).replace("-", ""));
	}
	
	public static long getyyyyMMddHHmmssSSSLong(long timeInMills) {
		return Long.valueOf(getyyyyMMddHHmmssSSS1Str(timeInMills));
	}
	
	public static String getyyyyMMddStr(Integer date) {
		if (date == null || date <= 0)
			throw new UnexpectedException("date illegal");
		return String.valueOf(date);
	}
	
}
